﻿layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(confirmInCoin)", function (data) {
        //获取防伪标记
        $.ajax({
            type: 'POST',
            url: '/InOutCash/ConfirmInCoin/',
            data: {
                Id: $("#Id").val(),  //主键
                ManagerRealName: $("#ManagerRealName").val(),  //主键
                ManagerCardNo: $("#ManagerCardNo").val(),
                UserRealName: $("#UserRealName").val(),  //主键
                UserCardNo: $("#UserCardNo").val()
            },
            dataType: "json",
            headers: {
                "X-CSRF-TOKEN-yilezhu": $("input[name='AntiforgeryKey_yilezhu']").val()
            },
            success: function (res) {//res为相应体,function为回调函数
                if (res.ResultCode == 200) {
                    var alertIndex = layer.alert(res.ResultMsg, { icon: 1 }, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                        top.layer.close(alertIndex);
                    });
                    //$("#res").click();//调用重置按钮将表单数据清空
                } else {
                    layer.alert(res.ResultMsg, { icon: 5 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
            }
        });
        return false;
    });

    //form.verify({
    //    alipay: function (value, item) { //value：表单的值、item：表单的DOM对象
    //        var val = parseFloat(value);
    //        if (!isNaN(val)) {
    //            if (val <= 0 || val > 6600) {
    //                return "单笔最高出金6600美元";
    //            }
    //        }
    //    }
    //});  

    function setQRCode() {
        ////text = 'HTTPS:\/\/QR.ALIPAY.COM\/tsx039507ncfffzkpbjqe68'
        var text = $("#hQRCode").val();
        if (text) {
            //// 设置参数方式
            //var qrcode = new QRCode('qrcode', {
            //    text: text,
            //    width: 168,
            //    height: 168,
            //    colorDark: '#000000',
            //    colorLight: '#ffffff',
            //    correctLevel: QRCode.CorrectLevel.M
            //});
            $("#QRCodeSrc").attr("src", text);
            var times = $("#times").val();
            if (times) {
                timer(parseInt(times));
            }
        } else {
            console.log('服务器忙，请稍后重试！');
        }
    }
    setQRCode();
    

    function timer(intDiff) {
        window.setInterval(function () {
            var day = 0,
                hour = 0,
                minute = 0,
                second = 0;//时间默认值       
            if (intDiff > 0) {
                day = Math.floor(intDiff / (60 * 60 * 24));
                hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute == 00 && second == 00) {
                //document.getElementById('qrcode').innerHTML = '<br/><br/><br/><h4>订单超时</h5><br/><br/>';
                alert('订单超时');
                javascript: history.back(-1);
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            //$('#day_show').html(day + "天");
            //$('#hour_show').html('<s id="h"></s>' + hour + '时');
            $('#minute_show').html('<s></s>' + minute + '分');
            $('#second_show').html('<s></s>' + second + '秒');
            intDiff--;
        }, 1000);
    } 
});

